package com.rent.message.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rent.common.entity.PageInfo;
import com.rent.common.entity.ResponseResult;
import com.rent.message.pojo.dto.ChatMessageQueryDto;
import com.rent.message.pojo.dto.UserId;
import com.rent.message.pojo.vo.MessageVo;
import com.rent.message.pojo.vo.MessagesListVo;
import com.rent.message.service.ChatMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/chat")
@Api(tags = "聊天消息接口")
@Slf4j
public class ChatMessageController {

    @Autowired
    private ChatMessageService chatMessageService;


    @ApiOperation(value = "获取用户的消息列表")
    @GetMapping("/getMessagesList")
    public ResponseResult<Page<MessagesListVo>> getMessagesList(PageInfo pageInfo){
        Page<MessagesListVo> messagesList = chatMessageService.getMessagesListByUserId(pageInfo);
        return ResponseResult.success(messagesList);
    }

    @ApiOperation(value = "获取和某个用户的消息记录")
    @GetMapping("/getMessages")
    public ResponseResult<List<MessageVo>> getMessages(ChatMessageQueryDto dto){
        List<MessageVo> messages = chatMessageService.getMessages(dto);
        return ResponseResult.success(messages);
    }

    @ApiOperation(value = "选中聊天对象")
    @PostMapping("/setChatUser")
    public ResponseResult<List<MessageVo>> setChatUser(@RequestBody UserId userId){

        List<MessageVo> messageVos = chatMessageService.setChatUser(userId.getUserId());
        return ResponseResult.success(messageVos);
    }

    @ApiOperation(value = "重置聊天对象为0")
    @PostMapping("/clearChatUser")
    public ResponseResult<List<MessageVo>> setChatUser(){
        chatMessageService.clearChatUser();
        return ResponseResult.success();
    }




}
